//
//  modifyUserInformation.m
//  SYDoorLock
//
//  Created by maple on 2016/11/7.
//  Copyright © 2016年 maplexk. All rights reserved.
//

#import "ModifyUserInformation.h"
#import "AFNetworking.h"

@implementation ModifyUserInformation{
    NSDictionary *_dic;
}

-(id)initWithDic:(NSDictionary *)dic{
    if (self = [super init]) {
        _dic = dic;
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/user/modify_user_info";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (id)requestArgument {
    NSMutableDictionary *dic = [NSMutableDictionary getPubdic];

    if (_dic[@"image"]) {
        [dic setObject:_dic[@"image"] forKey:@"image"];
        
    }
    
    if (_dic[@"nickname"]) {
        [dic setObject:_dic[@"nickname"] forKey:@"nickname"];
        
    }
    if (_dic[@"idcard"]) {
        [dic setObject:_dic[@"idcard"] forKey:@"idcard"];
        
    }
    if (_dic[@"realname"]) {
        [dic setObject:_dic[@"realname"] forKey:@"realname"];
    }
    if (_dic[@"sex"]) {
        [dic setObject:_dic[@"sex"] forKey:@"sex"];
        
    }
    if (_dic[@"birthday"]) {
        [dic setObject:_dic[@"birthday"] forKey:@"birthday"];
        
    }
    if (_dic[@"height"]) {
        [dic setObject:_dic[@"height"] forKey:@"height"];
        
    }
    if (_dic[@"weight"]) {
        [dic setObject:_dic[@"weight"] forKey:@"weight"];
    }
    
    if (_dic[@"province"]) {
        [dic setObject:_dic[@"province"] forKey:@"province"];
        
    }
    if (_dic[@"city"]) {
        [dic setObject:_dic[@"city"] forKey:@"city"];
    }
    
    NSString *sign=[NSString getSign:dic];
    [dic setObject:sign forKey:@"sign"];
    return dic;
    
}
- (AFConstructingBlock)constructingBodyBlock
{
    if ([NSData dataWithContentsOfFile:_dic[@"image"]] == nil) {
        return nil;
    }
    return ^(id<AFMultipartFormData> formData) {
        NSError *error;
        [formData appendPartWithFileURL:[NSURL fileURLWithPath:_dic[@"image"]] name:@"image" error:&error];
        //NSLog(@"formData = %@",formData);
        
    };
}

- (NSString *)userId {
    return [[[self responseJSONObject] objectForKey:@"userId"] stringValue];
}

-(void)dealloc
{
    //NSLog(@"modifyUserInformation dealloc");
}

@end
